package com.xiecong.service.impl;

import com.xiecong.mapper.EmpMapper;
import com.xiecong.mapper.StudentMapper;
import com.xiecong.pojo.ClazzData;
import com.xiecong.pojo.ClazzOption;
import com.xiecong.pojo.JobData;
import com.xiecong.pojo.JobOption;
import com.xiecong.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption empJobData() {
        // 查询员工职位与数量数据
        List<JobData> jobDataList = empMapper.empJobData();
        JobOption jobOption = new JobOption();
        if(!CollectionUtils.isEmpty(jobDataList)){
            //  封装到JobOption中
            // 把数据库查询到数据对象转成字符串集合，存放的职位名称
            List<String> jobList = jobDataList.stream().map(jobDate -> jobDate.getJob()).toList();
            jobOption.setJobList(jobList);
            // 把数据库查询到数据对象转成数字集合，存放的职位数量
            Stream<Integer> sataList = jobDataList.stream().map(JobData::getCount);
            jobOption.setDataList(sataList.toList());
        }
        return jobOption;
    }

    @Override
    public List<Map<String, Object>> genderData() {
        List<Map<String, Object>> genders = empMapper.genderData();
        return genders;
    }


    /**
     * 班级人数统计
     * @return
     */
    @Override
    public ClazzOption studentCount() {
        List<ClazzData> clazzDate = studentMapper.studentCount();
        ClazzOption clazzOption = new ClazzOption();
        List<String> clazzList = clazzDate.stream().map(clazzData -> clazzData.getClazzName()).toList();
        List<Integer> dataList = clazzDate.stream().map(clazzData -> clazzData.getStudentCount()).toList();
        clazzOption.setClazzList(clazzList);
        clazzOption.setDataList(dataList);
        return clazzOption;
    }


    /**
     * 学员学历统计
     */
    @Override
    public List<Map<String, Object>> studentDegreeData() {
        List<Map<String, Object>> studentDegreeData = studentMapper.studentDegreeData();
        return studentDegreeData;
    }


}
